﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Nave.Technique
{
    public class DynamicImage : Image
    {
        protected override void OnEnable()
        {
            base.OnEnable();
            if(sprite != null) DynamicAtlas.RegisImage(sprite);
        }

        protected override void OnDisable()
        {
            if (sprite) DynamicAtlas.Unregist(sprite);
            base.OnDisable();
        }

        public void SetSprite(Sprite sprite)
        {
            if(this.sprite) DynamicAtlas.Unregist(sprite);
            this.sprite = sprite;
            if (this.sprite) DynamicAtlas.RegisImage(sprite);
        }
    }
}